package cn.com.css.taxInspection.attention.controller;

import cn.com.css.taxInspection.attention.entity.JaajxxJaxcyyEntity;
import cn.com.css.taxInspection.attention.entity.JaajxxYjqlsjEntity;
import cn.com.css.taxInspection.attention.service.JaajxxJaxcyyService;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;



/**
 * ${comments}
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-05-13 10:03:39
 */
@Controller
@RequestMapping("/")
public class JaajxxJaxcyyController {
    @Resource
    private JaajxxJaxcyyService jaajxxJaxcyyService;
    @Resource
    private HttpSessionService httpSessionService;

    /**
    * 跳转到页面
    */
    @GetMapping("/index/jaajxxJaxcyy")
    public String jaajxxJaxcyy() {
        return "jaajxxjaxcyy/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("jaajxxJaxcyy/add")
    @ResponseBody
    public DataResult add(@RequestBody JaajxxJaxcyyEntity jaajxxJaxcyy){
        jaajxxJaxcyyService.save(jaajxxJaxcyy);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("jaajxxJaxcyy/delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        jaajxxJaxcyyService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("jaajxxJaxcyy/update")
    @ResponseBody
    public DataResult update(@RequestBody JaajxxJaxcyyEntity jaajxxJaxcyy){
        jaajxxJaxcyyService.updateById(jaajxxJaxcyy);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("jaajxxJaxcyy/listByPage")
    @ResponseBody
    public DataResult findListByPage(@RequestBody JaajxxJaxcyyEntity req){
        Page page = new Page(req.getPage(), req.getLimit());
        LambdaQueryWrapper<JaajxxJaxcyyEntity> queryWrapper = Wrappers.lambdaQuery();
        //queryWrapper.eq(JaajxxJaxcyyEntity::getYxbz, "Y");
        if(!StringUtils.isEmpty(req.getYxbz())){
            queryWrapper.eq(JaajxxJaxcyyEntity::getYxbz, req.getYxbz());
        }
        if(!StringUtils.isEmpty(req.getNsrsbh())){
            queryWrapper.eq(JaajxxJaxcyyEntity::getNsrsbh, req.getNsrsbh());
        }
        if(!StringUtils.isEmpty(req.getNsrmc())){
            queryWrapper.eq(JaajxxJaxcyyEntity::getNsrmc, req.getNsrmc());
        }
        if(!StringUtils.isEmpty(req.getAjbh())){
            queryWrapper.eq(JaajxxJaxcyyEntity::getAjbh, req.getAjbh());
        }
        IPage<JaajxxJaxcyyEntity> iPage = jaajxxJaxcyyService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "更新")
    @PutMapping("jaajxxJaxcyy/plupdatestatus")
    @ResponseBody
    public DataResult plupdatestatus(@RequestBody List<JaajxxJaxcyyEntity> jaajxxJaxcyyEntities){
        List<String> ids  = new ArrayList<>();
        for(JaajxxJaxcyyEntity obj:jaajxxJaxcyyEntities){
            ids.add(obj.getId());
        }
        UpdateWrapper<JaajxxJaxcyyEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.set("STATUS", "1");
        updateWrapper.set("UPDATE_TIME", new Date());
        updateWrapper.set("XGR_DM", httpSessionService.getCurrentUserId());
        jaajxxJaxcyyService.update(updateWrapper);
        return DataResult.success();
    }

}
